package nels4561;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;

import spacewar2.objects.Asteroid;
import spacewar2.objects.Base;
import spacewar2.objects.Beacon;
import spacewar2.objects.Ship;
import spacewar2.objects.SpacewarObject;
import spacewar2.simulator.Toroidal2DPhysics;

public class GlobalRepresentation 
{
	/**
	 * All the clusters in the Representation.
	 * */
	ArrayList<Cluster> allClusters;
	/**
	 * This cluster is used when finding each asteroid cluster.
	 * */
	Cluster cluster;
	
	GlobalRepresentation(Toroidal2DPhysics space, Ship ship)
	{
		//initialize variables
		cluster = null;
		allClusters = new ArrayList<Cluster>();
		Set<Asteroid> asteroids = space.getAsteroids();
		
		//for each mineable asteroid, find a cluster
		for(Asteroid asteroid : asteroids)
		{
			if(asteroid.isMineable())
			{
				cluster = new Cluster(space, ship, asteroid);
				allClusters.add(cluster);
			}	
		}
		
		//sort clusters based on their clusterValue
		Collections.sort(allClusters, new Comparator<Cluster>(){
			@Override
			public int compare(Cluster arg0, Cluster arg1) {
				if(arg0.clusterValue < arg1.clusterValue)
					return 1;
				return -1;
			}
		});
	}
}
